﻿Public Class frmFormaPago
    Dim res As DialogResult

    Private Sub frmFormaPago_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        Try
            listaFormaPago()

        Catch ex As Exception
            mensajeError(ex)
        End Try
    End Sub

    Private Sub btnIngresar_Click(sender As Object, e As EventArgs) Handles btnIngresar.Click
        Try
            If txtNombre.Text.Length > 0 Then
                ingresaFormaPago(txtNombre.Text)
                listaFormaPago()
                txtNombre.Clear()
            Else
                MessageBox.Show(msjCampoBlanco, msjTituloModal, MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
                txtNombre.Focus()

            End If

        Catch ex As Exception
            mensajeError(ex)
        End Try
    End Sub

    Private Sub btnEditar_Click(sender As Object, e As EventArgs) Handles btnEditar.Click
        Dim id As Integer
        Dim nom As String = ""


        Try

            With DGV_FormaPago

                If Not .CurrentRow.Selected Then
                    id = .Item(0, .CurrentCell.RowIndex).Value
                    nom = .Item(1, .CurrentCell.RowIndex).Value

                End If

            End With


            res = MessageBox.Show(msjActualizar, msjTituloModal, MessageBoxButtons.YesNo, MessageBoxIcon.Question)

            If res = DialogResult.Yes Then
                actualizaFormaPago(id, nom)
            End If




        Catch ex As Exception
            mensajeError(ex)

        End Try
    End Sub

    Private Sub btnEliminar_Click(sender As Object, e As EventArgs) Handles btnEliminar.Click
        res = MessageBox.Show("¿Esta seguro(a) de eliminar este campo?", "Coprevi", MessageBoxButtons.YesNo, MessageBoxIcon.Question)

        Try
            With DGV_FormaPago

                If Not .CurrentRow.IsNewRow And res = Windows.Forms.DialogResult.Yes Then
                    Dim id As Integer = .Item(0, .CurrentRow.Index).Value

                    eliminaFormaPago(id)
                    listaFormaPago()

                End If

            End With


        Catch ex As Exception
            mensajeError(ex)
        End Try
    End Sub
End Class